package com.seeyon.apps.kk.listener;

import com.seeyon.apps.collaboration.event.CollaborationStopEvent;
import com.seeyon.apps.collaboration.po.ColSummary;
import com.seeyon.apps.kk.manager.LockCaigouStopManager;
import com.seeyon.ctp.common.po.template.CtpTemplate;
import com.seeyon.ctp.util.annotation.ListenEvent;
import com.seeyon.kk.utils.ValueUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LockCaigouStopListener extends BaseListener{
	  private static final Log log = LogFactory.getLog(LockCaigouStopListener.class);
	  private LockCaigouStopManager lepmanager;
	  public LockCaigouStopManager getLepmanager() {
		return lepmanager;
	}

	public void setLepmanager(LockCaigouStopManager lepmanager) {
		this.lepmanager = lepmanager;
	}

	@ListenEvent(event=CollaborationStopEvent.class, async=true)
	  public void oneStart(CollaborationStopEvent event) throws Exception {
	    Thread.sleep(BaseListener.LISTENER_THREAD_SLEEPTIME);
	
	    String templetSubject = ValueUtils.getConfig().getString("kk.LockCaigouListener");
	
	    ColSummary summary = this.colManager.getColSummaryById(event.getSummaryId());
	    CtpTemplate template = this.templateManager.getCtpTemplate(summary.getTempleteId());
	    String[] templetSubjects = StringUtils.split(templetSubject, ",");
	
	    if (ArrayUtils.contains(templetSubjects, template.getTempleteNumber())) {
	      Long formid = summary.getFormRecordid();
	      this.lepmanager.addCaigouStopForm(formid);
	    }
	  }
}